<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>

<?php     
    
    $parent = 'clienteBusqueda';
    //variable de envio de informacion al menu Usuario ID
    $responseId         = $usuarioid;
    $idUser             = "idUser=".$usuarioid."&parent=".$parent;
    if (!$form->getObject()->isNew())
    $idUser            .= "&id=".$form->getObject()->getId();
    
    //Variable de la pagina
    $urlPage            = "Llamada";
    
    //Url de Actualizacion de Cliente Dashbioard
    $urlLoadUser        = "LoadUser('".url_for("dashboard/".$parent)."','".$idUser."','#User".$responseId."');";
    //Url de Actualizacion de Cliente Dashbioard / Cierre Ventana
    $urlLoadUserClose   = "javascritp:".$urlLoadUser."MenuClose();";
    //Url de Listar Atributos
    $urlListar          = "javascritp:LoadUser('".url_for('formulario/index'.$urlPage)."','".$idUser."','#slideDer-intConten');";
    //Url de Nuevo Atributo 
    $urlNew             = "javascritp:LoadUser('".url_for('formulario/new'.$urlPage)."','".$idUser."','#slideDer-intConten');";
    //Url de Delete Atributo 
    $urlDelete          = "javascritp:LoadUser('".url_for('formulario/delete'.$urlPage)."','".$idUser."','#slideDer-intConten');";
    
    
?>



<form class="filtroRangos" id="myForm<?php echo $urlPage; ?>" action="<?php echo url_for('producto/'.($form->getObject()->isNew() ? 'createMarcas' : 'updateMarca').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<table width="100%" cellpadding="0" cellspacing="0" border="0" id="tableRango">
    <tr>
        <td>
            <div class="title-windows">Programar Llamada
            
                <a href="javascript:void(0);" onclick="<?php echo $urlLoadUserClose; ?>" class="close-windows">
                    
                <img src="/images/icon/remove.png" title="Close"  />
                
                </a>
            </div>
        </td>
    </tr>
    <tr>
        <td class="" style="vertical-align:top; padding: 10px;">
            

        
        
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
      
      <tr>
          <td class="form-field" style="padding-top: 0px; margin-top: 0px;">
             
            <?php echo $form->renderGlobalErrors() ?>

             
            <?php echo $form['marca_id']->renderLabel() ?>
             <div class="clear" style="margin-bottom: 10px;"></div>
            <?php echo $form['marca_id']->renderError() ?>
            <?php echo $form['marca_id']; ?>
             <div class="clear"></div>
            <?php echo $form['usuario_id']; ?>
             <?php echo $form['usuario_id']->renderError(); ?>
          </td>
      </tr>    
          
      
  </table>


</td>
    </tr>
        <tr><td class="form-action-bottom">
            <!--Campo Oculto de evio de variable de ID del usuario-->
            <input type="hidden" name="usuarioids" value='<?php echo $responseId ?>'/>
            <input type="hidden" name="parent" value='<?php echo $parent ?>'/>
              
          
          <?php echo $form->renderHiddenFields(false) ?>
          <input class="button-submit" type="submit" value="Asignar"  id="submit"/>
          <a class="button-done" href="javascript:void(0);" onclick="<?php echo $urlLoadUserClose; ?>">Cerrar</a>
    
        </td></tr>

    
  </table>


</form>

<!--Ejecucion del Formulario por Jquery para evitar recarga-->
<script type="text/javascript">
    
   
// prepare tde form when tde DOM is ready
$(document).ready(function() {
    
    <?php 
    
    foreach ($favoritos as $favo){
        
        echo "$('#usuario_has_marca_marca_id_".$favo->getMarcaId()."').attr('checked', true);";
        
    }
    
    ?>
    
    
    var options = {
        target:        '#boxInput',   // target element(s) to be updated witd server response
        beforeSubmit:  showRequest,  // pre-submit callback
        success:       showResponse,  // post-submit callback
        type: 'post'       // 'get' or 'post', override for form's 'method' attribute

    };

    // bind form using 'ajaxForm'
    $('#myForm<?php echo $urlPage; ?>').ajaxForm(options);
});

// pre-submit callback
function showRequest(formData, jqForm, options) {
    // formData is an array; here we use $.param to convert it to a string to display it
    // but tde form plugin does tdis for you automatically when it submits tde data
    var queryString = $.param(formData);
    // here we could return false to prevent tde form from being submitted;
    // returning anytding otder tdan false will allow tde form submit to continue
    return true;
}

// post-submit callback
function showResponse(responseText, statusText, xhr, $form)  {
    
    
        
        
        $.ajax({
                url: '<?php echo url_for('dashboard/clienteBusqueda');?>',
                data: '<?php echo $idUser; ?>',
                type: 'POST',
                success: function(theResponse){
                    if(theResponse.match(/\d+/)==0){
                        $('#User<?php echo $responseId;?>').remove();
                        $('#LinUser<?php echo $responseId;?>').remove();
                    }else{
                        $('#User<?php echo $responseId;?>').html(theResponse);}
              }});
    
        <?php //echo $urlLoadUser;  ?>

       closeAll();    
     
}



</script>
